import Player from "./Player";

const { ccclass, property } = cc._decorator;



export class EffectBase {
    protected _id: number = null;
    protected _value: number = null;
    protected _target: Player = null;
    constructor(id: number, value: number, target: Player) {
        this._id = id;
        this._value = value;
        //需要增加特效的玩家
        this._target = target;
    }
    playerEffect() { }
}

export class AddBubble extends EffectBase {
    playerEffect(): void {
        if (this._value < 0) {
            this._target.playerDt.bubbleNum = this._target.playerDt.bubbleMaxNum;
            return;
        }
        this._target.playerDt.bubbleNum += this._value;
        if (this._target.playerDt.bubbleNum > this._target.playerDt.bubbleMaxNum) {
            this._target.playerDt.bubbleNum = this._target.playerDt.bubbleMaxNum
        }
    }
}

export class AddPower extends EffectBase {
    playerEffect(): void {
        if (this._value < 0) {
            this._target.playerDt.bubblePower = this._target.playerDt.bubbleMaxPower;
            return;
        }
        this._target.playerDt.bubblePower += this._value;
        if (this._target.playerDt.bubblePower > this._target.playerDt.bubbleMaxPower) {
            this._target.playerDt.bubblePower = this._target.playerDt.bubbleMaxPower;
        }
    }
}

export class AddSpeed extends EffectBase {
    playerEffect(): void {
        this._target.playerDt.speed += this._value;
    }
}

export class Reverse extends EffectBase {
    playerEffect(): void {
        //this._value表示翻转多少秒后恢复正常
        this._target.reverse(this._value);
    }
}

export const objEffect = {
    "4001": AddBubble,
    "4002": AddPower,
    "4003": AddPower,
    "4004": AddSpeed,
    "4005": AddBubble,
    "4006": Reverse,
}

export function getEffect(id: number, value: number, target: Player) {
    let objEffectType = objEffect[id];
    return new objEffectType(id, value, target);
}